Valid for Sitecore
6.x
How to auto-include configuration files?
Q:
How to auto-include configuration files?
A:
Auto-including configuration files.
New feature in Configuration.Factory allows to put an xml configuration file into /App_Config/Include and have it applied as a patch to Web.config at runtime. See the sample file content below:
<configuration >
<sitecore>
<connections>
<first x:before="web">Hello, World!</first>
<second x:after="master">Another Hello, world!</second>
<test>Test</test>
</connections>
<settings>
<setting name="WelcomeTitle">
<x:attribute name="value">Sitecore Rocks!</x:attribute>
</setting>
</settings>
</sitecore>
</configuration>
Implementation notes:
- The file must have <configuration> and <sitecore> elements, just like Web.config. At the moment only patching <sitecore> element is supported.
- For every element in the file Sitecore will find matching element in Web.config with the same name and set of attributes and their values. If there is none, the element will be inserted to Web.config tree.
- Extension attributes and elements are defined in namespace http://www.sitecore.net/xmlconfig/, the local prefix does not matter.
- The following extensions are supported:
- x:attribute element allows to add/update attribute value in Web.config. Put it in the element you want to update.
- x:before and x:after attributes specify insertion point when inserting new element. Both accept an XPath relative to the parent node of inserted element.
Tips and Tricks:
- Elements specified in config file are used for search, so put only the necessary minimum of attributes. Use x:attribute to add/update more attributes.
<configuration >
<sitecore>
<sites>
<site name="website"> <!-- Search for site[@id='website'] -->
<x:attribute name="content">master</x:attribute>
</site>
</sites>
</sitecore>
</configuration>
- To insert an element as first one in the use x:before="*[1]"
<configuration >
<sitecore>
<connections>
<first x:before="*[1]">First connection string</first>
</connections>
</sitecore>
</configuration>